package queue;

import java.util.Scanner;

public class Esercise1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str="";
        boolean isFlag=false;
        Queue queue = new Queue(4);
        for (int i =0;i<queue.getMaxSize();i++){
            System.out.println("请输入字符：");
            String str1 = scanner.next();
            char c1 = str1.charAt(0);
            queue.addQueue(c1);
            str+=c1;
        }
        System.out.println("你输入的字符串为："+str);
        for(int i =queue.getMaxSize()-1;i>=0;i--){
            char c = str.charAt(i);
            if(!(queue.getQueueHead()==str.charAt(i))){
                isFlag=true;
                break;
            }
        }
        if(isFlag){
            System.out.println(str+"不是回文串");
        }else {
            System.out.println(str+"是回文串");
        }
    }
}
class Queue{
    private int maxSize;
    private int font;
    private int rear;
    private char[] arr;

    public Queue(int maxSize) {
        this.maxSize = maxSize;
        arr = new char[maxSize];
    }

    public int getMaxSize() {
        return maxSize;
    }

    public boolean isEmpty(){
        return font==rear;
    }
    public boolean isFull(){
        return rear==maxSize;
    }
    public void addQueue(char o){
        if(isEmpty()){
            arr[rear++]= o;
            return;
        }
        if(isFull()){
            throw new RuntimeException("队列已满");
        }
        arr[rear++]=o;
//        System.out.println("add"+o);
    }
    public  char getQueueHead(){
        if(isEmpty()){
            throw new RuntimeException("队列已空");
        }
        return arr[font++];
    }
    public void showQueue(){
        if (isEmpty()){
            System.out.println("队列为空");
            return;
        }
        for(int i = font ; i<maxSize ;i++){
            System.out.println(arr[i]);
        }
    }
}
